/*
 * @Author: alonez
 * @Date: 2021-02-26 13:36:34
 * @LastEditTime: 2021-06-09 09:50:13
 * @Description: 缓存工具类
 */

import Taro from '@tarojs/taro';

const setItem = async (key: string, val: any) => {
  return await Taro.setStorage({ key, data: val });
};

const setItemSync = (key: string, val: any) => {
  Taro.setStorageSync(key, val);
};

const getItem = async (key: string) => {
  return await Taro.getStorage({ key });
};

const getItemSync = (key: string) => {
  return Taro.getStorageSync(key);
};

const removeItem = async (key: string) => {
  return await Taro.removeStorage({ key });
};

const removeItemSync = (key: string) => {
  Taro.removeStorageSync(key);
};

const clear = async () => {
  return await Taro.clearStorage();
};

const clearSync = () => {
  Taro.clearStorageSync();
};

const getInfoSync = () => {
  return Taro.getStorageInfoSync();
};

export { setItem, setItemSync, getItem, getItemSync, removeItem, removeItemSync, clear, clearSync, getInfoSync };
